package com.vf.admin.utils;

import com.mortennobel.imagescaling.ResampleOp;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class PicUtils {
    public static void main(String[] args){
        File fromFile = new File("H://11/1.jpg");
        File toFile = new File("H://11/2.jpg");
        PicUtils.resize(fromFile,toFile,200,200,"JPEG");
    }

    public static void resize(File fromFile, File toFile,int newWidth, int newHeight, String formatName) {
        try {
            BufferedImage inputBufImage = ImageIO.read(fromFile);
            ResampleOp resampleOp = new ResampleOp(newWidth, newHeight);// 转换
            BufferedImage rescaledTomato = resampleOp.filter(inputBufImage,null);
            ImageIO.write(rescaledTomato, formatName, toFile);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
